package com.grass.p019lv.novel.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.grass.p019lv.bean.SearchNovelHotRecommendBean;
import com.grass.p019lv.databinding.FragmentSearchHotNovelBinding;
import com.grass.p019lv.novel.activity.NovelActivity;
import com.grass.p019lv.novel.activity.VoiceNovelActivityNew;
import com.grass.p019lv.novel.adapter.AdapterSearchHotRecommend;

/* renamed from: com.grass.lv.novel.fragment.SearchHotNovelFragment */
public class SearchHotNovelFragment extends LazyFragment<FragmentSearchHotNovelBinding> {
    private AdapterSearchHotRecommend adapterSearchHotRecommend;
    private int fictionType;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_search_hot_novel;
    }

    public static SearchHotNovelFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        SearchHotNovelFragment searchHotNovelFragment = new SearchHotNovelFragment();
        bundle.putInt("search_hot_type", i);
        searchHotNovelFragment.setArguments(bundle);
        return searchHotNovelFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.fictionType = bundle.getInt("search_hot_type");
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.adapterSearchHotRecommend = new AdapterSearchHotRecommend();
        ((FragmentSearchHotNovelBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        ((FragmentSearchHotNovelBinding) this.binding).recycler.setAdapter(this.adapterSearchHotRecommend);
        this.adapterSearchHotRecommend.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.novel.fragment.SearchHotNovelFragment.C32021 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                if (!SearchHotNovelFragment.this.isOnClick()) {
                    if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                        new BuyVipDialog(SearchHotNovelFragment.this.getContext()).show();
                    } else if (1 == SearchHotNovelFragment.this.fictionType) {
                        int fictionId = ((SearchNovelHotRecommendBean.SearchNovelHotRecommendData) SearchHotNovelFragment.this.adapterSearchHotRecommend.getDataInPosition(i)).getFictionId();
                        Intent intent = new Intent(SearchHotNovelFragment.this.getActivity(), NovelActivity.class);
                        intent.putExtra(Key.NOVEL_ID, fictionId);
                        SearchHotNovelFragment.this.getActivity().startActivity(intent);
                    } else {
                        int fictionId2 = ((SearchNovelHotRecommendBean.SearchNovelHotRecommendData) SearchHotNovelFragment.this.adapterSearchHotRecommend.getDataInPosition(i)).getFictionId();
                        Intent intent2 = new Intent(SearchHotNovelFragment.this.getActivity(), VoiceNovelActivityNew.class);
                        intent2.putExtra(Key.NOVEL_ID, fictionId2);
                        SearchHotNovelFragment.this.getActivity().startActivity(intent2);
                    }
                }
            }
        });
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (!NetUtil.isNetworkAvailable()) {
            ((FragmentSearchHotNovelBinding) this.binding).statusLayout.showNoNet();
            return;
        }
        ((FragmentSearchHotNovelBinding) this.binding).statusLayout.showLoading();
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelHotSearch(this.fictionType, 30), new HttpCallback<BaseRes<SearchNovelHotRecommendBean>>("queryHotSearch") {
            /* class com.grass.p019lv.novel.fragment.SearchHotNovelFragment.C32032 */

            public void onLvSuccess(BaseRes<SearchNovelHotRecommendBean> baseRes) {
                if (SearchHotNovelFragment.this.binding != null) {
                    ((FragmentSearchHotNovelBinding) SearchHotNovelFragment.this.binding).statusLayout.hideLoading();
                    if (baseRes.getCode() != 200) {
                        ((FragmentSearchHotNovelBinding) SearchHotNovelFragment.this.binding).statusLayout.showError();
                    } else if (baseRes.getData() == null || baseRes.getData().getData() == null || baseRes.getData().getData().size() <= 0) {
                        ((FragmentSearchHotNovelBinding) SearchHotNovelFragment.this.binding).statusLayout.showEmpty();
                    } else {
                        SearchHotNovelFragment.this.adapterSearchHotRecommend.setData(baseRes.getData().getData());
                    }
                }
            }
        });
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        HttpUtils.getInsatance().cancelTag("queryHotSearch");
        super.onDestroyView();
    }
}
